#!/usr/bin/env node

/**
 * Created by JasonChou on 16/6/6.
 */
var program = require('commander');
var fs = require('fs');
var s = require("underscore.string");
var mutationFile = './src/store/mutationTypes.js';


function list(v) {
  return v.split(',');
}

program.usage('[options] <file ...>').//
option('-m --mutationTypeList <items>', 'add a type to mutation', list).//
option('-r --mutationRequestTypeList <items>', 'add a request type to mutation', list).//
option('-i --api', 'create api').//
parse(process.argv);


if (program.mutationTypeList) {
  program.mutationTypeList.forEach(function (type) {
    addMutationType(type);
  });
} else if (program.mutationRequestTypeList) {
  program.mutationRequestTypeList.forEach(function (type) {

    fs.appendFileSync(mutationFile, '\n');

    addMutationType(type + '_' + 'request');
    addMutationType(type + '_success');
    addMutationType(type + '_failure');
  });
}else


function addMutationType(type) {
  var tmp = type.toUpperCase();
  var data = 'export const ' + tmp + ' = \'' + tmp + '\'; \n';
  fs.appendFileSync(mutationFile, data);
}

